/*
 * ColorSchemeMapperNormal.java
 *
 * Copyright(c) 2011
 * Michael Kroez
 * kroez@studiorutton.de
 *
 * All rights reserved.
 *
 * $Id$
 * 
 */

package de.studiorutton.colorschemes;

import de.studiorutton.gerengdic.R;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;

public abstract class ColorSchemeMapper extends DrawableFactory implements
		IColorSchemeMapper {
	protected Resources res;

	protected GradientColor titleGradient;
	protected GradientColor resultGradient;
	protected GradientColor itemGradient;

	protected ColorCollection lightLowContrast;
	protected ColorCollection darkLowContrast;
	protected ColorCollection lightHighContrast;
	protected ColorCollection darkHighContrast;
	
	protected Drawable lightLowContrastArrow;
	protected Drawable darkLowContrastArrow;
	protected Drawable lightHighContrastArrow;
	protected Drawable darkHighContrastArrow;

	protected boolean indexedInverse = false;
	protected ITitleStyle titleStyle;
	
	public ColorSchemeMapper(Resources res) {
		this.res = res;

		createColors();
		createArrows();

	}
	
	public ITitleStyle getTitleStyle() {
		return titleStyle;
	}
	public void setTitleStyle( ITitleStyle titleStyle) {
		this.titleStyle = titleStyle;
	}

	public abstract void createColors();
	
	public void createArrows() {
		
		lightLowContrastArrow  = res.getDrawable(getArrowLightVerySmall()).mutate();
		createFiltered( lightLowContrastArrow, lightLowContrast.textColor );
		
		darkLowContrastArrow = res.getDrawable(getArrowLightVerySmall()).mutate();
		createFiltered( darkLowContrastArrow, darkLowContrast.textColor );
		
		if ( lightHighContrast != null ) {
			lightHighContrastArrow = res.getDrawable(getArrowLightVerySmall()).mutate();
			createFiltered( lightHighContrastArrow, lightHighContrast.textColor );
		}
		
		if ( darkHighContrast != null ) {
			darkHighContrastArrow = res.getDrawable(getArrowLightVerySmall()).mutate();
			createFiltered( darkHighContrastArrow, darkHighContrast.textColor );
		}
	}
	
	public int getBackgroundColor() {
		return Color.BLACK;
	}
	
	public boolean isDividerSet() {
		return true;
	}
	
	public Drawable getListDividerDrawable() {
		return res.getDrawable( R.drawable.divider_transparent );
	}

	//
	// Indexed Dictionary
	//

	public void setIndexedInverse(boolean inverse) {
		indexedInverse = inverse;
	}

	// Title
	public Drawable getResultTitleBackground() {
		ColorCollection cc, ccSelected;
		if (indexedInverse) {
			cc = darkLowContrast;
			ccSelected = lightLowContrast;
		}
		else {
			cc = lightLowContrast;
			ccSelected = darkLowContrast;
		}
			
		Drawable normalD = createGradientDrawable(GradientWay.ONE_TWO, titleGradient, cc,
				RoundCorner.TOP);
		Drawable selectedD = createGradientDrawable(GradientWay.ONE_TWO, titleGradient, ccSelected,
				RoundCorner.TOP);
		return createSelectedUnSelectedDrawable( normalD, selectedD );
	}

	public int getResultTitleTextcolor() {
		if (indexedInverse)
			return darkLowContrast.textColor;
		else
			return lightLowContrast.textColor;
	}

	public Drawable getResultTitleArrow() {
		if ( indexedInverse )
			return darkLowContrastArrow;
		else
			return lightLowContrastArrow;
	}

	// Content
	public Drawable getResultContentBackground(boolean isLast) {
		ColorCollection cc;
		if (indexedInverse)
			cc = lightLowContrast;
		else
			cc = darkLowContrast;

		RoundCorner rc;
		if (isLast)
			rc = RoundCorner.BOTTOM;
		else
			rc = RoundCorner.NO;

		return createGradientDrawable(GradientWay.ONE_TWO_ONE, resultGradient,
				cc, rc);
	}

	public int getResultContentTextcolor() {
		if (indexedInverse)
			return lightLowContrast.textColor;
		else
			return darkLowContrast.textColor;
	}

	public Drawable getResultContentArrow() {
		if ( indexedInverse )
			return lightLowContrastArrow;
		else
			return darkLowContrastArrow;
	}

	//
	// Dictionary Activity / History
	//

	// One
	public Drawable getResultContentBackgroundOne() {
//		return createGradientDrawable(GradientWay.ONE_TWO_ONE,
//				itemGradient, darkLowContrast, RoundCorner.BOTH);
		ColorCollection cc = darkLowContrast;
		ColorCollection ccSelected = lightLowContrast;
		
			
		Drawable normalD = createGradientDrawable(GradientWay.ONE_TWO_ONE, itemGradient, cc,
				RoundCorner.BOTH);
		Drawable selectedD = createGradientDrawable(GradientWay.ONE_TWO_ONE, itemGradient, ccSelected,
				RoundCorner.BOTH);
		return createSelectedUnSelectedDrawable( normalD, selectedD );
	}

	public int getResultContentTextcolorOne() {
		return darkLowContrast.textColor;
	}

	public Drawable getResultContentArrowOne() {
		return darkLowContrastArrow;
	}

	// Two
	public Drawable getResultContentBackgroundTwo() {
//		return createGradientDrawable(GradientWay.ONE_TWO_ONE,
//				itemGradient, darkLowContrast, RoundCorner.BOTH);
		
		ColorCollection cc = darkLowContrast;
		ColorCollection ccSelected = lightLowContrast;
		
			
		Drawable normalD = createGradientDrawable(GradientWay.ONE_TWO_ONE, itemGradient, cc,
				RoundCorner.BOTH);
		Drawable selectedD = createGradientDrawable(GradientWay.ONE_TWO_ONE, itemGradient, ccSelected,
				RoundCorner.BOTH);
		return createSelectedUnSelectedDrawable( normalD, selectedD );

		
	}

	public int getResultContentTextcolorTwo() {
		return darkLowContrast.textColor;
	}

	public Drawable getResultContentArrowTwo() {
		return darkLowContrastArrow;
	}
	
	// Inside Content
	public Drawable getResultContentInsideBackground() {
		return createGradientDrawable(GradientWay.ONE_TWO,
				titleGradient, lightLowContrast, RoundCorner.TOP);
	}

	public int getResultContentInsideTextcolor() {
		return lightLowContrast.textColor;
	}

	public Drawable getResultContentInsideArrow() {
		return lightLowContrastArrow;
	}

	//
	// Update Actiity
	//

	public Drawable getUpdateItemBackground() {
		return createGradientDrawable(GradientWay.ONE_TWO_ONE,
				itemGradient, darkLowContrast, RoundCorner.BOTH);
	}

	public int getUpdateItemTextcolor() {
		return darkLowContrast.textColor;
	}

	//
	// About Activity
	//

//	public int getAboutContentTextcolor() {
//		return getTextColorDark();
//	}

	//
	// From ColorScheme
	//
	
//	public int getTextColorLight() {
//		return Color.WHITE;
//	}
//
//	public int getTextColorDark() {
//		return Color.BLACK;
//	}

	public int getArrowLightVerySmall() {
		return R.drawable.chevron_medium_thin_2_white;
	}

	public int getArrowDarkVerySmall() {
		return R.drawable.chevron_medium_thin_2;
	}

}
